/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.mode;

import deatax.GameData;
import deatax.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 *
 * @author Pieman
 */
public class CivilisationGameMode extends GameMode {

    int goal;
    int def;
    public CivilisationGameMode(GameData data) {
        super(data);
        desc = "Civilisation. The first player to reach a certain population wins.";
        reqs = new String[] {"Population"};
        reqv = new String[] {"3000"};
        def = 3000;
    }

    @Override
    public void setArgs(String[] args) {
        try {
            goal = Integer.parseInt(args[1]);
        } catch (Exception ex) {
            goal = def;
        }
    }
    

    @Override
    public void populationChanged(Player p, int total) {
        super.populationChanged(p, total);
        if (total >= goal) {
            //win
        }
    }
    
    @Override
    public ArrayList<Player> getResultOrder() {
        ArrayList<Player> order = data.getRoster().getPlayers();
        Collections.sort(order, new PopulationOrder());
        
        
        ArrayList<Player> losers = data.getRoster().getLosers();
        for (int i = losers.size() - 1; i >= 0; --i) {
            order.add(losers.get(i));
        }
        return order;
    }
    
    private class PopulationOrder implements Comparator<Player> {

        @Override
        public int compare(Player o1, Player o2) {
            
            return o1.getTotalPopulation() - o2.getTotalPopulation();
        }
        
        
    } 
}
